﻿using System;
using System.Collections;
using System.Collections.Generic;
using TrueSync;
using Network;
[System.Serializable]
public class HitFlyState : StateBase//吹飞硬直,跟击退硬直的区别是击退硬直如果到了边缘就推释放者但是吹飞不会
{
    FP mXTranslateLength;

    LogicMoveComponent mMoveComponent;
    FP mInitXPosition;

    public override StateEnum StateName
    {
        get
        {
            return StateEnum.HitFly;
        }
    }

    public override bool IsFinished()
    {
        return FP.Abs(mMoveComponent.Position.x - mInitXPosition) >= mXTranslateLength;
    }

    public override void Enter(LogicEntity lEntity, StateBase lastState, object[] stateParams)
    {
        base.Enter(lEntity, lastState, stateParams);
        mXTranslateLength = (FP)stateParams[0];
        FP xTranslateSpeed = (FP)stateParams[1];

        mMoveComponent = mLEntity.GetLogicComponent<LogicMoveComponent>();
        mInitXPosition = mMoveComponent.Position.x;
        mMoveComponent.MoveSpeed = new TSVector2(xTranslateSpeed * mMoveComponent.FaceDirection, 0);
    }

    public override void Excute(FP deltaTime)
    {
        if (statusComponent.HP <= 0)
        {
            mLEntity.GetLogicComponent<LogicStateMachineComponent>().ChangeState(StateEnum.Dead);
            return;
        }

        if (statusComponent.Dizzy <= 0)
        {
            mLEntity.GetLogicComponent<LogicStateMachineComponent>().ChangeState(StateEnum.Dizzy);
            return;
        }

        if (IsFinished())
        {
            LogicStateMachineComponent stateMachineComponent = mLEntity.GetLogicComponent<LogicStateMachineComponent>();
            stateMachineComponent.ChangeState(StateEnum.KnockdownHit);
        }
    }

    public override void Exit()
    {
        mMoveComponent = null;
        base.Exit();
    }

    public override void OnStimulate(Stimulate stimulate)
    {
        LogicStateMachineComponent stateMachineComponent = mLEntity.GetLogicComponent<LogicStateMachineComponent>();
        switch (stimulate.StimulateType)
        {
            case StimulateTypeEnum.HitFloatStimulate:
            case StimulateTypeEnum.FalldownStimulate:
            case StimulateTypeEnum.HitFlyStimulate:
            case StimulateTypeEnum.HitBackStimulate:
                HitBackStimulate hitflyStimulate = (HitBackStimulate)stimulate;
                stateMachineComponent.ChangeState(StateEnum.JumpHit);
                break;
            case StimulateTypeEnum.ThrowStimulate:
                stateMachineComponent.ChangeState(StateEnum.ThrowHit);
                break;
        }
    }
}
